from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-05 14:03:00.003878
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 05, Jun, 2022
Time: 14:03:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5145
Nobs: 678.000 HQIC: -49.8821
Log likelihood: 8420.41 FPE: 1.72034e-22
AIC: -50.1144 Det(Omega_mle): 1.50795e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.306841 0.059235 5.180 0.000
L1.Burgenland 0.105471 0.038405 2.746 0.006
L1.Kärnten -0.109159 0.020217 -5.399 0.000
L1.Niederösterreich 0.200369 0.079949 2.506 0.012
L1.Oberösterreich 0.120892 0.078915 1.532 0.126
L1.Salzburg 0.255627 0.040892 6.251 0.000
L1.Steiermark 0.046427 0.053576 0.867 0.386
L1.Tirol 0.105361 0.043374 2.429 0.015
L1.Vorarlberg -0.060393 0.038164 -1.582 0.114
L1.Wien 0.033213 0.070038 0.474 0.635
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.042822 0.125659 0.341 0.733
L1.Burgenland -0.033073 0.081471 -0.406 0.685
L1.Kärnten 0.039876 0.042888 0.930 0.352
L1.Niederösterreich -0.184776 0.169602 -1.089 0.276
L1.Oberösterreich 0.440753 0.167409 2.633 0.008
L1.Salzburg 0.285382 0.086748 3.290 0.001
L1.Steiermark 0.108779 0.113654 0.957 0.339
L1.Tirol 0.315530 0.092013 3.429 0.001
L1.Vorarlberg 0.026385 0.080960 0.326 0.744
L1.Wien -0.034165 0.148577 -0.230 0.818
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187243 0.030433 6.153 0.000
L1.Burgenland 0.087982 0.019731 4.459 0.000
L1.Kärnten -0.007612 0.010387 -0.733 0.464
L1.Niederösterreich 0.256525 0.041075 6.245 0.000
L1.Oberösterreich 0.147984 0.040544 3.650 0.000
L1.Salzburg 0.045113 0.021009 2.147 0.032
L1.Steiermark 0.025162 0.027525 0.914 0.361
L1.Tirol 0.086114 0.022284 3.864 0.000
L1.Vorarlberg 0.053089 0.019607 2.708 0.007
L1.Wien 0.119526 0.035983 3.322 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110487 0.030653 3.604 0.000
L1.Burgenland 0.043426 0.019874 2.185 0.029
L1.Kärnten -0.013724 0.010462 -1.312 0.190
L1.Niederösterreich 0.184807 0.041373 4.467 0.000
L1.Oberösterreich 0.319016 0.040837 7.812 0.000
L1.Salzburg 0.103233 0.021161 4.878 0.000
L1.Steiermark 0.109968 0.027725 3.966 0.000
L1.Tirol 0.098692 0.022445 4.397 0.000
L1.Vorarlberg 0.062824 0.019749 3.181 0.001
L1.Wien -0.019680 0.036244 -0.543 0.587
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121394 0.056564 2.146 0.032
L1.Burgenland -0.046351 0.036673 -1.264 0.206
L1.Kärnten -0.046136 0.019306 -2.390 0.017
L1.Niederösterreich 0.145662 0.076345 1.908 0.056
L1.Oberösterreich 0.153853 0.075358 2.042 0.041
L1.Salzburg 0.282574 0.039049 7.236 0.000
L1.Steiermark 0.053384 0.051160 1.043 0.297
L1.Tirol 0.166489 0.041419 4.020 0.000
L1.Vorarlberg 0.096633 0.036443 2.652 0.008
L1.Wien 0.074830 0.066881 1.119 0.263
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061693 0.044707 1.380 0.168
L1.Burgenland 0.029979 0.028986 1.034 0.301
L1.Kärnten 0.051649 0.015259 3.385 0.001
L1.Niederösterreich 0.204230 0.060341 3.385 0.001
L1.Oberösterreich 0.310848 0.059561 5.219 0.000
L1.Salzburg 0.042589 0.030863 1.380 0.168
L1.Steiermark 0.009963 0.040436 0.246 0.805
L1.Tirol 0.133141 0.032736 4.067 0.000
L1.Vorarlberg 0.067835 0.028804 2.355 0.019
L1.Wien 0.088587 0.052861 1.676 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169645 0.053469 3.173 0.002
L1.Burgenland 0.005557 0.034667 0.160 0.873
L1.Kärnten -0.064991 0.018249 -3.561 0.000
L1.Niederösterreich -0.092079 0.072168 -1.276 0.202
L1.Oberösterreich 0.195670 0.071235 2.747 0.006
L1.Salzburg 0.056094 0.036912 1.520 0.129
L1.Steiermark 0.239467 0.048361 4.952 0.000
L1.Tirol 0.503391 0.039153 12.857 0.000
L1.Vorarlberg 0.061303 0.034449 1.779 0.075
L1.Wien -0.071742 0.063222 -1.135 0.256
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153190 0.059687 2.567 0.010
L1.Burgenland 0.000386 0.038698 0.010 0.992
L1.Kärnten 0.060840 0.020372 2.986 0.003
L1.Niederösterreich 0.188454 0.080561 2.339 0.019
L1.Oberösterreich -0.073394 0.079519 -0.923 0.356
L1.Salzburg 0.210435 0.041205 5.107 0.000
L1.Steiermark 0.133247 0.053985 2.468 0.014
L1.Tirol 0.073293 0.043706 1.677 0.094
L1.Vorarlberg 0.144236 0.038456 3.751 0.000
L1.Wien 0.111338 0.070574 1.578 0.115
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374754 0.035127 10.669 0.000
L1.Burgenland -0.002388 0.022774 -0.105 0.916
L1.Kärnten -0.022124 0.011989 -1.845 0.065
L1.Niederösterreich 0.214576 0.047411 4.526 0.000
L1.Oberösterreich 0.221478 0.046798 4.733 0.000
L1.Salzburg 0.041246 0.024250 1.701 0.089
L1.Steiermark -0.015669 0.031771 -0.493 0.622
L1.Tirol 0.097729 0.025721 3.800 0.000
L1.Vorarlberg 0.056090 0.022632 2.478 0.013
L1.Wien 0.036193 0.041534 0.871 0.384
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037821 0.122658 0.181945 0.145329 0.105128 0.087344 0.040900 0.213526
Kärnten 0.037821 1.000000 -0.018104 0.134677 0.053422 0.092557 0.441049 -0.058776 0.094416
Niederösterreich 0.122658 -0.018104 1.000000 0.328167 0.133223 0.286540 0.083242 0.169136 0.306158
Oberösterreich 0.181945 0.134677 0.328167 1.000000 0.223453 0.314306 0.173211 0.159382 0.258575
Salzburg 0.145329 0.053422 0.133223 0.223453 1.000000 0.133310 0.102954 0.119888 0.133975
Steiermark 0.105128 0.092557 0.286540 0.314306 0.133310 1.000000 0.144403 0.123988 0.058186
Tirol 0.087344 0.441049 0.083242 0.173211 0.102954 0.144403 1.000000 0.079355 0.153600
Vorarlberg 0.040900 -0.058776 0.169136 0.159382 0.119888 0.123988 0.079355 1.000000 0.017215
Wien 0.213526 0.094416 0.306158 0.258575 0.133975 0.058186 0.153600 0.017215 1.000000